from etgui import *
import CmdNo
from PyDialog import PyDialog
from PageLayout import MakeDialogWithButtons
import string

class SimpleTextDialog(PyDialog):
	def __init__(self, title, label='', text=''):
		PyDialog.__init__(self)
		self.title = title
		self.textitem = None
		self.labelitem = None
		self.SetText(text)
		self.SetLabel(label)
	def SetText(self, text):
		text = string.join(string.split(text,'@'),'@@')
		if not self.textitem:
			self.textitem = self.MakeTextItem(text)
		else:
			self.textitem.SetString(text)
	def MakeTextItem(self, text):
		return MultilineTextItem(text, -1, gFixedFont)
	def SetLabel(self, label):
		if not self.labelitem:
			self.labelitem = TextItem(-1,label,gFixedFont)
		else:
			self.labelitem.SetString(label)
	def ShowUnderMouse(self):
		return self.impl.ShowUnderMouse()
	def MakeContent(self):
		return VExpander(
			items=(
				self.labelitem,
				Scroller(self.textitem,Point(600,200)),
				Separator(),
				AlignBox(eVObjHRight,
					flags=eVObjVFixed,
					inner=HBox( 
						align=eVObjHRight,
						items= self.MakeButtons()
					)
				)
			)
		)
	def MakeButtons(self):
		return (
			ActionButton(CmdNo.cIdCancel,"Done",default=1),
		)

gDialog = None
def Show(text="bla\nbla\nbla\n"):
	global gDialog
	if not gDialog:
		gDialog = SimpleTextDialog('Test','TestText:',text)
		gDialog.impl = MakeDialog(gDialog)
	gDialog.ShowUnderMouse()

gOutputDialog = None
def ShowOutput(cmd, output):
	global gOutputDialog
	if not gOutputDialog:
		gOutputDialog = SimpleTextDialog('Command Output')
		gOutputDialog.impl = MakeDialog(gOutputDialog)
	gOutputDialog.SetLabel(cmd)
	gOutputDialog.SetText(output)
	gOutputDialog.ShowUnderMouse()

